<html>
<head><meta charset="utf-8"><title>Allocator vs GlobalAlloc trait types · t-libs/wg-allocators · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/index.html">t-libs/wg-allocators</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/Allocator.20vs.20GlobalAlloc.20trait.20types.html">Allocator vs GlobalAlloc trait types</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="226438245"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/Allocator%20vs%20GlobalAlloc%20trait%20types/near/226438245" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> CPerezz <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/Allocator.20vs.20GlobalAlloc.20trait.20types.html#226438245">(Feb 15 2021 at 22:36)</a>:</h4>
<p>Hi.<br>
I started to take a look to the <code>Allocator</code> and <code>GlobalAllocator</code> in <code>core::alloc</code> and there's something I'm not really sure about.<br>
After <a href="https://github.com/rust-lang/rust/commit/ab9362ad9a9b4b93951ccb577224dda367923226">https://github.com/rust-lang/rust/commit/ab9362ad9a9b4b93951ccb577224dda367923226</a> I understand that when we implement <code>Allocator</code> we want <code>allocate</code> to return <code>Result&lt;NonNull&lt;[u8]&gt;, AllocError&gt;</code>. But then it's weird that <code>GlobalAlloc::alloc</code> requires to return <code>*mut u8</code> since you cannot re-use the previous impl to be called from this one IIUC. At least I don't see any methods that do not require experimental features in order to go from <code>NonNull&lt;u8&gt;</code> to <code>NonNull&lt;[u8]&gt;</code> &amp; viceversa.</p>
<p>Is there anything I'm missing? Or is this just a WIP(being reworked/refactored)? In case it is, the only way now to implement an allocator is to have sepparated impls for <code>core::Allocator</code> and <code>GlobalAlloc</code>? Or to enable <code>#![feature(nonnull_slice_from_raw_parts)]</code> &amp; <code>#![feature(slice_ptr_get)]</code> basically.</p>
<p>Thanks!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>